<%inherit file="base.html"/>

<%def name="head()">
<title>在线用户管理</title>
<script>

function busy(flag) {
    if (flag) {
        $(".dorelease").attr("disabled", "disabled"); 
        $("#realse_all").attr("disabled", "disabled");    
        $("#query_action").attr("disabled", "disabled");    
    } else {
        $(".dorelease").removeAttr("disabled");
        $("#realse_all").removeAttr("disabled");
        $("#query_action").removeAttr("disabled");
    }
}


function unlock_online(obj,username, nas_addr,session_id){
    busy(true);
    param = {
        'username': username,
        'nas_addr': nas_addr,
        'session_id':session_id,
        '_xsrf': '${handler.xsrf_token}'
    }
    if(obj){
        $(obj).attr("disabled","disabled")
    }
    $.post("/admin/customer/online/unlock", param, function (ev) {
        console.log(ev);
        alert(ev.msg);
        busy(false);
        window.location.reload();
    }, "json");
}

$(document).ready(function (){
    $("#realse_all").click(function(){
        var nas_addr = $("#nas_addr").val();
        if(nas_addr.length == 0)
        {
            alert("请选择bas");
            return false;
        }
        if(confirm("是否解锁该bas下所有用户?"))
        {
             unlock_online('','',nas_addr,'')
        }
    });

});



</script>

</%def>

<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-users"></i>
            <h3 class="box-title">在线用户管理</h3>
        </div>
        <div class="box-body">
            <div class="container">

        <form id="query_form" class="form-horizontal form-well" role="form" action="/admin/customer/online" method="post">
        ${xsrf_form_html()}
            <div class="form-group">
                <label for="node_id" class="col-md-2 control-label">区域</label>
                <div class="col-md-3">
                    <select id="node_id" name="node_id" class="form-control" onchange="whenNodeChange()">
                        <option></option>
                        % for node in node_list:
                          <option value="${node.id}" ${str(node.id)==node_id and "selected" or ""}>${node.node_desc}</option>
                        % endfor
                    </select>
                </div>
                <label for="account_number" class="col-md-2 control-label">用户账号</label>
                <div class="col-md-3">
                    <input type="text" id="account_number" name="account_number" class="form-control" placeholder="模糊查询" value=${account_number or ""} >
                </div>
            </div>

            <div class="form-group">
                 <label for="framed_ipaddr" class="col-md-2 control-label">IP地址</label>
                <div class="col-md-3">
                    <input id="framed_ipaddr"  name="framed_ipaddr" class="form-control" type="text" value=${ip_addr or ""}>
                </div>


                <label for="mac_addr" class="col-md-2 control-label">MAC地址</label>
                <div class="col-md-3">
                    <input type="text" id="mac_addr" name="mac_addr" class="form-control" value=${mac_addr or ""}>
                </div>
            </div>

            <div class="form-group">

                <label for="nas_addr" class="col-md-2 control-label">选择bas</label>
                <div class="col-md-3">
                     <select id="nas_addr" name="nas_addr" class="form-control">
                        <option></option>
                        % for bas in bas_list:
                          <option value="${bas.ip_addr}" ${bas.ip_addr== nas_addr and "selected" or ""}>${bas.bas_name}</option>
                        % endfor
                    </select>
                </div>

            </div>

            <div class="form-group">
                <div class="col-md-offset-5 col-md-7">
                    <button type="submit" id="query_action" class="btn btn-primary">查询</button>&nbsp;&nbsp;
                    % if int(current_user.opr_type) == 0 :
                    <button type="button" id="realse_all" class="btn btn-default" >BAS用户下线</button>
                    % endif
                </div>
            </div>
        </form>


        <table class="table table-hover">
            <thead>
            <tr>
                <th>用户姓名</th> 
                <th>用户账号</th>
                <th>BAS地址</th>
                <th>上线时间</th>
                <th>IP地址</th>
                <th>MAC地址</th>
                <th>在线时间</th>
                <th>上传/下载</th>
                <th></th>
            </tr>
            </thead>

            <tbody>
                % for online in page_data.result:
            <tr>
                <td>${online.realname}</td>
                <td>${online.account_number}</td>
                <td>${online.nas_addr}</td>
                <td>${online.acct_start_time}</td>
                <td>${online.framed_ipaddr}</td>
                <td>${online.mac_addr}</td>
                <td>${utils.fmt_online_time(online.acct_start_time)}</td>
                <td>${utils.kb2mb(online.input_total)}M/${utils.kb2mb(online.output_total)}M</td>
                <td>
                <a class="opt-btn btn-default dorelease" href="javascript:unlock_online(this,'${online.account_number}','${online.nas_addr}','${online.acct_session_id}');">解锁</a>
                </td>
            </tr>
                % endfor
            </tbody>

        </table>
        ${page_data.render(form_id="query_form")}

    </div>
</div>
</div>
</section>
</%def>
